package com.mvc4g.example.client;

public class CalculatorModel implements Constants {

	private static CalculatorModel singleton = new CalculatorModel();

	private int number1 = 0;
	private int number2 = 0;
	private String operator = ADD;

	private CalculatorModel() {

	}

	static public CalculatorModel getUniqueInstance() {
		return singleton;
	}

	public String enterOperator(String operator) {

		doOperation();

		this.operator = operator;

		return Integer.toString(number1);
	}

	public String enterNumber(int number) {
		number2 = number2 * 10 + number;
		return Integer.toString(number2);
	}

	private void doOperation() {
		if (ADD.equals(operator)) {
			number1 += number2;

		} else if (LESS.equals(operator)) {
			number1 -= number2;
		}

		number2 = 0;

	}
}
